<?php

require_once 'Zend/Controller/Front.php';
require_once 'Zend/View/Helper/Url.php';

class Zend_View_Helper_Route extends Zend_View_Helper_Url
{
	/*  
		Removed module from: 
		http://ishouldbecoding.com/2008/07/12/simplifying-zend_view_helper_url 
	*/
    public function route($controller = null, $action = null, $params = array(), $route = null)
    {
        $front = Zend_Controller_Front::getInstance();
        $request = $front->getRequest();
        $router = $front->getRouter();
        
        if ($action === null) {
            $action = $request->getActionName();
        }
        if ($controller === null) {
            $controller = $request->getControllerName();
        }
        
        $urlOptions = array_merge($params, array(
            'action' => $action,
            'controller' => $controller
        ));
        
        if ($router->hasRoute($controller) && $route === null) {
            $route = $controller;
        } else if ($route === null) {
            $route = 'default';
        }
        
        return $this->url($urlOptions, $route, true);
    }
}